set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR riscv64)
if(DEFINED ENV{RISCV_ROOT_PATH})
    file(TO_CMAKE_PATH $ENV{RISCV_ROOT_PATH} RISCV_ROOT_PATH)
else()
    message(FATAL_ERROR "RISCV_ROOT_PATH env must be defined")
endif()

set(RISCV_ROOT_PATH ${RISCV_ROOT_PATH} CACHE STRING "root path to riscv toolchain")

set(CMAKE_C_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-linux-gnu-g++")

set(CMAKE_FIND_ROOT_PATH "${RISCV_ROOT_PATH}/riscv64-unknown-linux-gnu")

set(CMAKE_SYSROOT "${RISCV_ROOT_PATH}/sysroot")

set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_C_FLAGS "-O3 -mcpu=c920 -march=rv64gcv0p7_xtheadc -mtune=c920 -mabi=lp64d -g")
set(CMAKE_CXX_FLAGS "-O3 -mcpu=c920 -march=rv64gcv0p7_xtheadc -mtune=c920 -mabi=lp64d -g")


cmake_minimum_required(VERSION 3.0)
project(Yolo_detect)

# OpenCV
# set(OpenCV_DIR "/home/zxy/packages/OpenCV/build_opt/install/lib/cmake/opencv4" CACHE PATH "OpenCV")
set(OpenCV_DIR "/home/zxy/packages/opencv-4.6.0/build" CACHE PATH "OpenCVConfig.cmake")
find_package(OpenCV REQUIRED core videoio)

# OpenMP
find_package(OpenMP REQUIRED)
if(OPENMP_FOUND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

add_subdirectory(benchmark)

# ncnn
set(ncnn_DIR "/home/zxy/packages/ncnn/build/install/lib/cmake/ncnn" CACHE PATH "ncnnConfig.cmake")
find_package(ncnn REQUIRED)


include_directories(include)
set(SRC_FILES
     src/yolov5_detect.cpp
     src/draw_objects.cpp
     src/main.cpp
    # src/test.cpp
)

add_executable(demo ${SRC_FILES})

target_link_libraries(demo PRIVATE ${OpenCV_LIBS} ncnn OpenMP::OpenMP_CXX)
